package com.tianji.learning.controller;


import com.tianji.common.domain.dto.PageDTO;
import com.tianji.common.domain.query.PageQuery;
import com.tianji.common.exceptions.BadRequestException;
import com.tianji.learning.domain.dto.QuestionFormDTO;
import com.tianji.learning.domain.query.QuestionPageQuery;
import com.tianji.learning.domain.vo.QuestionVO;
import com.tianji.learning.service.IInteractionQuestionService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 互动提问的问题表 前端控制器
 * </p>
 *
 * @author liuchun
 * @since 2024-08-30
 */
@RestController
@RequestMapping("/questions")
public class InteractionQuestionController {

    @Autowired
    private IInteractionQuestionService questionService;


    @ApiOperation("新增提问")
    @PostMapping
    public void saveQuestion(@Valid @RequestBody QuestionFormDTO questionFormDTO) {
         questionService.saveQuestion(questionFormDTO);
    }

    @ApiOperation("修改提问")
    @PutMapping("/{id}")
    public void updateQuestion(@PathVariable Long id, @RequestBody QuestionFormDTO questionFormDTO) {
         questionService.updateQuestion(id, questionFormDTO);
    }
    @ApiOperation("用户端分页查询提问")
    @GetMapping("/page")
    public PageDTO<QuestionVO> pageQuestion(QuestionPageQuery query) {
        return questionService.pageQuestion(query);
    }
    @ApiOperation(("根据id查询问题详情"))
    @GetMapping("/{id}")
    public QuestionVO getQuestionById(@PathVariable Long id) {
        return questionService.getQuestionById(id);
    }
    @ApiOperation("删除我的问题")
    @DeleteMapping("/{id}")
    public void deleteQuestion(@PathVariable Long id) {
         questionService.deleteQuestion(id);
    }
}
